Skip to content

Add -n/--tail support to lstk logs#359

Open
gtsiolis wants to merge 1 commit into
mainfrom
pro-358-support-n-tail-n-in-lstk-logs
Open

Add -n/--tail support to lstk logs#359
gtsiolis wants to merge 1 commit into
mainfrom
pro-358-support-n-tail-n-in-lstk-logs

Conversation

@gtsiolis

@gtsiolis gtsiolis commented Jul 2, 2026

Copy link
Copy Markdown
Member

Motivation

DevRel parity report: the Python CLI supports localstack logs -n 20 to inspect the last N log lines, while lstk logs only offered all-or-follow — cumbersome on a busy emulator and a migration papercut. -n, --tail (default all) is also the exact convention of docker logs, docker compose logs, and nerdctl logs.

Changes

  • Add -n, --tail to lstk logs (string, default "all", wording identical to docker logs); validated at the command boundary — non-negative integer or all
  • Thread the value through container.Logs / ui.RunLogs into runtime.StreamLogs, which previously hardcoded Tail: "all"
  • --follow --tail N shows the last N lines and then streams (handled natively by the Docker API)
  • Regenerate MockRuntime for the StreamLogs signature change

Tail applies to raw log lines before the noise filter (docker semantics), so --tail 20 can display fewer than 20 lines unless -v is passed.

Tests

  • New integration tests, red-green verified: --tail/-n limit output, default shows all lines, invalid values are rejected with a helpful error, and --follow --tail starts from the tail
  • Manually verified against a real container in both plain and TUI (PTY) modes, including --tail 0, --tail all, over-count values, and combined -fn 3

Closes PRO-358

@gtsiolis gtsiolis added semver: minor docs: needed Pull request requires documentation updates labels Jul 2, 2026
@gtsiolis gtsiolis self-assigned this Jul 2, 2026
@gtsiolis
gtsiolis force-pushed the pro-358-support-n-tail-n-in-lstk-logs branch 4 times, most recently from cff248a to b3e7ad8 Compare July 9, 2026 07:11
@gtsiolis
gtsiolis force-pushed the pro-358-support-n-tail-n-in-lstk-logs branch 4 times, most recently from 80c342e to 52b13c3 Compare July 17, 2026 13:47
@gtsiolis
gtsiolis marked this pull request as ready for review July 17, 2026 13:48
@gtsiolis
gtsiolis requested a review from a team as a code owner July 17, 2026 13:48
@gtsiolis
gtsiolis force-pushed the pro-358-support-n-tail-n-in-lstk-logs branch from 52b13c3 to a8809b2 Compare July 20, 2026 07:16
@gtsiolis
gtsiolis force-pushed the pro-358-support-n-tail-n-in-lstk-logs branch from a8809b2 to a3a8697 Compare July 21, 2026 07:08

@skyrpex skyrpex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tail value is computed before filtering, so the output is confusing in some scenarios. For example, when the latest log entries are of type INFO:

$ ./bin/lstk logs --verbose
emulator |
emulator | LocalStack version: 2026.6.3
emulator | LocalStack build date: 2026-07-15
emulator | LocalStack build git hash: 7bf63b7c4
emulator |
emulator | 2026-07-21T12:19:57.291  INFO --- [  MainThread] l.p.c.b.licensingv2        : Successfully activated cached license cc9b6903-7df5-4afb-9d50-f27d7c
           9a4cf5:enterprise from /var/lib/localstack/cache/license.json 🔑✅
emulator | 2026-07-21T12:20:00.115  INFO --- [  MainThread] l.p.c.extensions.plugins   : loaded 0 extensions
emulator | Ready.
emulator | 2026-07-21T12:20:02.016  INFO --- [et.reactor-2] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200
emulator | 2026-07-21T12:20:02.017  INFO --- [et.reactor-1] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200
emulator | 2026-07-21T12:20:02.017  INFO --- [et.reactor-0] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200
emulator | 2026-07-21T12:20:02.024  INFO --- [et.reactor-1] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200
emulator | 2026-07-21T12:20:02.025  INFO --- [et.reactor-2] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200
emulator | 2026-07-21T12:20:02.026  INFO --- [et.reactor-0] localstack.request.http    : GET /_localstack/pods/state/metamodel => 200

For reference, this is the $ ./bin/lstk logs output:

emulator |
emulator | LocalStack version: 2026.6.3
emulator | LocalStack build date: 2026-07-15
emulator | LocalStack build git hash: 7bf63b7c4
emulator |
emulator | 2026-07-21T12:19:57.291  INFO --- [  MainThread] l.p.c.b.licensingv2        : Successfully activated cached license cc9b6903-7df5-4afb-9d50-f27d7c
           9a4cf5:enterprise from /var/lib/localstack/cache/license.json 🔑✅
emulator | 2026-07-21T12:20:00.115  INFO --- [  MainThread] l.p.c.extensions.plugins   : loaded 0 extensions
emulator | Ready.

Now, if I run ./bin/lstk logs --tail 1 the output is empty as it's tailed on the full set first, and then filtered afterwards. What I expect, as a user, is the following:

$ ./bin/lstk logs --tail 1
emulator | Ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: needed Pull request requires documentation updates semver: minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants